/**
 * Copyright (c) 2020 lizebang
 *
 * This software is released under the MIT License.
 * https://opensource.org/licenses/MIT
 */

package config

type Fragment struct {
	Includes []string  `yaml:"includes,omitempty"`
	Projects []Project `yaml:"projects,omitempty" validate:"dive,required"`
}

type Project struct {
	before []Plugin
	after  []Plugin

	Name     string            `yaml:"name" validate:"required"`
	Order    int               `yaml:"order" validate:"required_with=Plugins"`
	Args     map[string]string `yaml:"args,omitempty"`
	Type     string            `yaml:"type" validate:"required"`
	From     string            `yaml:"from" validate:"required"`
	To       string            `yaml:"to" validate:"required"`
	Interval int               `yaml:"interval,omitempty" validate:"min=0"`
	Plugins  []Plugin          `yaml:"plugins,omitempty" validate:"omitempty"`
}

func (p *Project) GetPlugins() ([]Plugin, []Plugin) {
	return p.before, p.after
}

type Plugin struct {
	Name  string            `yaml:"name" validate:"required"`
	Order int               `yaml:"order" validate:"required"`
	Args  map[string]string `yaml:"args,omitempty"`
}
